var mygrid = null;
function doActionWork(url, eid,stepId,actionId,name) {
	doPost(url, $.param({
		"workflowId" : eid,
		"stepId":stepId,
		"actionId":actionId,
		"userView" : true,
		"workflowName.workflowName":name
	}));
}

function doWatchFormatter(cellvalue, options, rowObject) {
	// alert(cellvalue);
	var wid = rowObject['workflowId'];
	var url = "workflow/proceed/watch?workflowId="+cellvalue;
	var link = jQuery("<a onclick=\"doGet('" + url
			+ "');return false;\"></a>");
	link.attr("href", "javascript:;");
	link.text("监控");
	var sp = $("<span></span>").append(link);	
	return sp.html(); 
}

function doBackFormatter(v,opt,row){
	
	var sp = $("<span></span>");	
	if (row['state'] == 1) {		
		var link2 = $("<a>回退</a>");
		link2.attr("href","javascript:rollback("+v+");");
		sp.append(link2);
	}
	return sp.html();
}
function doRemoveFormatter(v,opt,row){
	
	var sp = $("<span></span>");	
	if (row['state'] == 1) {		
		var link3 = jQuery("<a style='color:red'></a>");
		link3.attr("href", "javascript:killWorkflow('" + v + "');");
		link3.text("删除");
		sp.append(link3);
	}
	return sp.html();
}
function doCompleteFormatter(v,opt,row){
	
	var sp = $("<span></span>");	
	if (row['state'] == 1) {		
		var link2 = jQuery("<a style='color:green'></a>");
		link2.attr("href", "javascript:completeWorkflow('" + v + "');");
		link2.text("结束");
		sp.append(link2);
	}
	return sp.html();
}

function doFormFormatter(v,opt,row){
	var sp = $("<span></span>");	
	var link2 = jQuery("<a style='color:green'></a>");
	link2.attr("href", "javascript:openForm('" + v + "');");
	link2.text("表单");
	sp.append(link2);
	return sp.html();
}
function openForm(id){
	window.open('admin/form/show/generate-html!viewform?workflowId='+id,'formwin')
}
function doOfficeFormatter(v,opt,row){
	var sp = $("<span></span>");	
	var link2 = jQuery("<a style='color:green'></a>");
	link2.attr("href", "javascript:openOffice('" + v + "');");
	link2.text("文档");
	sp.append(link2);
	return sp.html();
}

function openOffice(id){
	window.open('workflow/read-office?workflowId='+id,'officewin');
}

function completeWorkflow(id){
	if(!confirm("确定执行该操作吗?")){
		return;
	}
	var url = "workflow/proceed/proceed!complete?workflowId="+id;
	$.ajax({
		url:url,
		success:function(){
			reloadGrid();
		}
	});
}

function killWorkflow(id){
	if(!confirm("确定执行该操作吗?")){
		return;
	}
	var url = "workflow/proceed/proceed!delete?workflowId="+id;
	$.ajax({
		url:url,
		success:function(){
			reloadGrid();
		}
	});
}
function rollback(id){
	if(!confirm("确定执行该操作吗?")){
		return;
	}
	var url="workflow/proceed/proceed!rollback";
	var data = "workflowId="+id;
	doSubmit(url,data,function(){
		reloadGrid();
	});
}
function reloadGrid(){
	mygrid.trigger("reloadGrid");
}